package myTest.classAndInterface

import myTest.enumPackage.Gender

/**
 * 默认Public修饰符修饰类，默认生成get,set方法，默认生成带参构造(无参构造不见了)
 * 这种类称为值对象
 * 声明变量val==final，只读；var可变
 * val,var用于成员变量或者局部变量，方法参数不带
 *
 */
class Person(val id: Int, var name: String, val gender: Gender) {


    /**
     * 变量属性名以is开头，get方法前缀不变
     * 自定义访问器，可以初始化变量的初始值
     * 不能使用var
     */
    val isMarried: Boolean
        get() {
            return id > 1
        }

    val isMan: Boolean
        get() = (gender==Gender.MAN)



    override fun equals(other: Any?): Boolean {
//        if (this === other) return true
//        if (javaClass != other?.javaClass) return false

        other as Person

        if (id != other.id) return false
        if (name != other.name) return false
        if (gender != other.gender) return false

        return true
    }

    override fun hashCode(): Int {
        var result = id
        result = 31 * result + name.hashCode()
        result = 31 * result + gender.hashCode()
        return result
    }



}